﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using Graffiti.Core;

namespace GraffitiExtras.Plugins.SpamCommentNotification
{
    public class SpamCommentNotification : GraffitiEvent
    {
        #region EditableForm members

        public override string Name
        {
            get
            {
                return "Disable Spam Comment Notification";
            }
        }

        public override string Description
        {
            get
            {
                return "Plug-in to disable email notifications for spam comments. " +
                    "By <a href=\"http://nayyeri.net\"> Keyvan Nayyeri</a>.";
            }
        }

        public override bool IsEditable
        {
            get
            {
                return false;
            }
        }

        #endregion

        #region GraffitiEvent members

        public override void Init(GraffitiApplication ga)
        {
            ga.BeforeInsert += new DataObjectEventHandler(ga_BeforeInsert);
        }

        void ga_BeforeInsert(DataBuddyBase dataObject, EventArgs e)
        {
            Comment feedback = dataObject as Comment;

            if (feedback != null)
            {

                int threshold = int.Parse(ConfigurationManager.AppSettings["Graffiti:Spam:Score"]);

                if (feedback.SpamScore >= threshold)
                    feedback.DontSendEmail = true;
            }
        }

        #endregion
    }
}
